/*
 * @Description: 
 * @Author: liyuhao
 * @Date: 2021-08-05 15:47:37
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-11-15 14:57:55
 */

//表单数字验证
export const NumberValidator = (_: any, value: string) => {
    if (value !== undefined && value !== null && isNaN(Number(value))) {
        return Promise.reject('请输入数字')
    }
    return Promise.resolve()
}

//数字范围验证
export const NumberRangeValidator = (rule?: {
    min?: number,
    max?: number
}) => (_: any, value: string) => {
    const { min, max } = rule || {}
    const _value = Number(value)
    if (value !== undefined && value !== null && isNaN(_value)) {
        return Promise.reject('请输入数字')
    }
    if (((min || min == 0) && _value < min) || ((max || max == 0) && _value > max)) {
        return Promise.reject()
    }
    return Promise.resolve()
}

export const cellPhonePattern = /^1[3456789]\d{9}$/

export const passwordPattern = /^.*(?=.{8,20})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[,~!@#$%^&*?\(\)]).*$/

export const namePattern = /^[\w]{1,100}$/

export const relaNamePattern = /^[A-Za-z0-9\u4E00-\u9FA5]{1,20}$/
